from django.db import models

# Create your models here.


class Area(models.Model):
    """省市区"""
    name = models.CharField(max_length=100, verbose_name='名称')
    parent = models.ForeignKey('self',
                               on_delete=models.SET_NULL,
                               related_name='subs',
                               null=True,
                               blank=True,
                               verbose_name='上级行政区')

    # related_name, 关联名字默认是 类名_set, 可以通过related_name进行修改
    # bookname:
    # rolename, foreignkey(book),  在book中 自动添加role_set， 如果需要修改其名称，则使用related_name
    class Meta:
        db_table = 'tb_areas'
        verbose_name = '省市区'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

